
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"

********************************************************************************
********************************************************************************
**# TABLE H.2

use "${Intermediate}\Combined for forloops.dta", clear

keep if inlist(item, "co", "se", "obs")
gen 	keeping = 1 if inlist(outcome, "earn", "empl", "home", "eshu", "move") 
replace keeping = 1 if inlist(outcome, "inde", "cred", "zero", "deli", "auto")
keep if keeping==1
keep if inlist(time, "q0104", "q0508")
keep if inlist(spec, "ivac")
keep if group=="a" 
keep if geo=="c" | geo=="n"

gen 	base = "_base" 		if geo=="c"
replace base = "_notbase" 	if geo=="n"

drop geo

* T-TESTS

replace value = subinstr(value, "(", "", .)	
replace value = subinstr(value, ")", "", .)	
replace value = subinstr(value, ",", "", .)	
replace value = subinstr(value, "*", "", .)	
destring(value), replace 

reshape wide value, i(outcome spec time group base) j(item) string 
reshape wide valueco valuese valueobs, i(outcome spec time group) j(base) string 

rename value* *
rename *_base base_*
rename *_notbase notbase_*

// create standard deviation variable for ttesti command
gen base_sd = base_se * sqrt(base_obs)
gen notbase_sd = notbase_se * sqrt(notbase_obs)

order base_obs base_co base_sd notbase_obs notbase_co notbase_sd
gen pvalue_sd = .
gen pvalue_se = .

forval i=1(1)20 {
	
	di `i'
	
	levelsof base_obs in `i', 	clean local(b_obs)
	levelsof base_co in `i', 	clean local(b_co)
	levelsof base_sd in `i', 	clean local(b_sd)
	
	levelsof notbase_obs in `i', 	clean local(nb_obs)
	levelsof notbase_co in `i', 	clean local(nb_co)
	levelsof notbase_sd in `i', 	clean local(nb_sd)
	
	levelsof base_se in `i', 	clean local(b_se)
	levelsof notbase_se in `i', clean local(nb_se)
	
	ttesti `b_obs' `b_co' `b_sd' `nb_obs' `nb_co' `nb_sd'
	replace pvalue_sd = r(p) in `i'
	
	ttesti `b_obs' `b_co' `b_se' `nb_obs' `nb_co' `nb_se' // i think this is wrong
	replace pvalue_se = r(p) in `i'
	
	
}

keep outcome spec time pvalue_sd 
gen value = string(pvalue, "%10.3fc")
drop pvalue

gen 	group = "x"
gen 	item = "pv"
gen 	geo = "x"

order outcome group spec time item value 

* ADD BACK THE FULL DATA

append using "${Intermediate}\Combined for forloops.dta"

gen 	keeping = 1 if inlist(outcome, "earn", "empl", "home", "eshu", "move") 
replace keeping = 1 if inlist(outcome, "inde", "cred", "zero", "deli", "auto")
keep if keeping==1
keep if inlist(time, "q0104", "q0508")
keep if inlist(spec, "ivac")

levelsof outcome, local(outcomes)
levelsof group, local(groups)
levelsof spec, local(specs)
levelsof time, local(times)
levelsof geo, local(geos)
levelsof item, local(items)

foreach outx in `outcomes' {
	local id1 = "`outx'"
	
	foreach grox in `groups' {
		local id2 = "`grox'"
		
		foreach spex in `specs' {
			local id3 = "`spex'"
			
			foreach timx in `times' {
				local id4 = "`timx'"
				
				foreach geox in `geos' {
					local id5 = "`geox'"
					
					foreach itex in `items' {
						local id6 = "`itex'"
		
					levelsof value if 	outcome=="`outx'" & ///
										group=="`grox'" & ///
										spec=="`spex'" & ///
										time=="`timx'" & ///
										geo=="`geox'" & ///
										item=="`itex'" , ///
						clean local(`id1'_`id2'_`id3'_`id4'_`id5'_`id6')
						di "`id1'_`id2'_`id3'_`id4'_`id5'_`id6'"
						
					}
				}
			}
		}
	}
}

			

texdoc init "${Outputs}/Supplementary data_Table_H2.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c c c c c c} \hline \toprule ///
	& \multicolumn{3}{c}{\textbf{1-4 Quarters After Filing}} ///
	& & \multicolumn{3}{c}{\textbf{5-8 Quarters After Filing}} \\

tex \cmidrule{2-4} \cmidrule{6-8}	
	
tex  & Cook	& New York 	& p-value	& & Cook 	& New York 	& p-value \\
tex & (1) 		& (2) 	& (3)		& & (4) 	& (5) 	& (6) \\

tex \cmidrule{2-4} \cmidrule{6-8}

tex \multicolumn{8}{l}{\textbf{\underline{Labor market outcomes}}} \\
tex $x ~~~Earnings: 	& `earn_a_ivac_q0104_c_co' 		& `earn_a_ivac_q0104_n_co' 		& `earn_x_ivac_q0104_x_pv' & ///
							& `earn_a_ivac_q0508_c_co' 		& `earn_a_ivac_q0508_n_co' 		& `earn_x_ivac_q0508_x_pv' \\	
tex							& `earn_a_ivac_q0104_c_se' 		& `earn_a_ivac_q0104_n_se' 		& & ///
							& `earn_a_ivac_q0508_c_se' 		& `earn_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`earn_a_ivac_q0104_c_obs']   & [`earn_a_ivac_q0104_n_obs']	& &	///
							& [`earn_a_ivac_q0508_c_obs']   & [`earn_a_ivac_q0508_n_obs']	& \\

tex \multicolumn{8}{l}{ } \\
tex $x ~~~Employment: 	& `empl_a_ivac_q0104_c_co' 		& `empl_a_ivac_q0104_n_co' 		& `empl_x_ivac_q0104_x_pv' & ///
							& `empl_a_ivac_q0508_c_co' 		& `empl_a_ivac_q0508_n_co' 		& `empl_x_ivac_q0508_x_pv' \\	
tex							& `empl_a_ivac_q0104_c_se' 		& `empl_a_ivac_q0104_n_se' 		& & ///
							& `empl_a_ivac_q0508_c_se' 		& `empl_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`empl_a_ivac_q0104_c_obs']   & [`empl_a_ivac_q0104_n_obs']	& &	///
							& [`empl_a_ivac_q0508_c_obs']   & [`empl_a_ivac_q0508_n_obs']	& \\
							
tex \multicolumn{8}{l}{ } \\

tex \multicolumn{8}{l}{\textbf{\underline{Housing outcomes}}} \\

tex $x ~~~Not at eviction address: 	& `move_a_ivac_q0104_c_co' 		& `move_a_ivac_q0104_n_co' 		& `move_x_ivac_q0104_x_pv' & ///
							& `move_a_ivac_q0508_c_co' 		& `move_a_ivac_q0508_n_co' 		& `move_x_ivac_q0508_x_pv' \\	
tex							& `move_a_ivac_q0104_c_se' 		& `move_a_ivac_q0104_n_se' 		& & ///
							& `move_a_ivac_q0508_c_se' 		& `move_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`move_a_ivac_q0104_c_obs']   & [`move_a_ivac_q0104_n_obs']	& &	///
							& [`move_a_ivac_q0508_c_obs']   & [`move_a_ivac_q0508_n_obs']	& \\

tex \multicolumn{8}{l}{ } \\							
tex $x ~~~Emergency shelter: 	& `eshu_a_ivac_q0104_c_co' 		& `eshu_a_ivac_q0104_n_co' 		& `eshu_x_ivac_q0104_x_pv' & ///
							& `eshu_a_ivac_q0508_c_co' 		& `eshu_a_ivac_q0508_n_co' 		& `eshu_x_ivac_q0508_x_pv' \\	
tex							& `eshu_a_ivac_q0104_c_se' 		& `eshu_a_ivac_q0104_n_se' 		& & ///
							& `eshu_a_ivac_q0508_c_se' 		& `eshu_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`eshu_a_ivac_q0104_c_obs']   & [`eshu_a_ivac_q0104_n_obs']	& &	///
							& [`eshu_a_ivac_q0508_c_obs']   & [`eshu_a_ivac_q0508_n_obs']	& \\
							
tex \multicolumn{8}{l}{ } \\							
tex $x ~~~Any homelessness services: 	& `home_a_ivac_q0104_c_co' 		& `home_a_ivac_q0104_n_co' 		& `home_x_ivac_q0104_x_pv' & ///
							& `home_a_ivac_q0508_c_co' 		& `home_a_ivac_q0508_n_co' 		& `home_x_ivac_q0508_x_pv' \\	
tex							& `home_a_ivac_q0104_c_se' 		& `home_a_ivac_q0104_n_se' 		& & ///
							& `home_a_ivac_q0508_c_se' 		& `home_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`home_a_ivac_q0104_c_obs']   & [`home_a_ivac_q0104_n_obs']	& &	///
							& [`home_a_ivac_q0508_c_obs']   & [`home_a_ivac_q0508_n_obs']	& \\
							
tex \multicolumn{8}{l}{ } \\	

tex \multicolumn{8}{l}{\textbf{\underline{Financial health outcomes}}} \\
						
tex $x ~~~Financial health index: 	& `inde_a_ivac_q0104_c_co' 		& `inde_a_ivac_q0104_n_co' 		& `inde_x_ivac_q0104_x_pv' & ///
							& `inde_a_ivac_q0508_c_co' 		& `inde_a_ivac_q0508_n_co' 		& `inde_x_ivac_q0508_x_pv' \\	
tex							& `inde_a_ivac_q0104_c_se' 		& `inde_a_ivac_q0104_n_se' 		& & ///
							& `inde_a_ivac_q0508_c_se' 		& `inde_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`inde_a_ivac_q0104_c_obs']   & [`inde_a_ivac_q0104_n_obs']	& &	///
							& [`inde_a_ivac_q0508_c_obs']   & [`inde_a_ivac_q0508_n_obs']	& \\
							
tex \multicolumn{8}{l}{ } \\							
tex $x ~~~Credit score: 	& `cred_a_ivac_q0104_c_co' 		& `cred_a_ivac_q0104_n_co' 		& `cred_x_ivac_q0104_x_pv' & ///
							& `cred_a_ivac_q0508_c_co' 		& `cred_a_ivac_q0508_n_co' 		& `cred_x_ivac_q0508_x_pv' \\	
tex							& `cred_a_ivac_q0104_c_se' 		& `cred_a_ivac_q0104_n_se' 		& & ///
							& `cred_a_ivac_q0508_c_se' 		& `cred_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`cred_a_ivac_q0104_c_obs']   & [`cred_a_ivac_q0104_n_obs']	& &	///
							& [`cred_a_ivac_q0508_c_obs']   & [`cred_a_ivac_q0508_n_obs']	& \\

tex \multicolumn{8}{l}{ } \\							
tex $x ~~~No open revolving account: & `zero_a_ivac_q0104_c_co' 		& `zero_a_ivac_q0104_n_co' 		& `zero_x_ivac_q0104_x_pv' & ///
							& `zero_a_ivac_q0508_c_co' 		& `zero_a_ivac_q0508_n_co' 		& `zero_x_ivac_q0508_x_pv' \\	
tex							& `zero_a_ivac_q0104_c_se' 		& `zero_a_ivac_q0104_n_se' 		& & ///
							& `zero_a_ivac_q0508_c_se' 		& `zero_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`zero_a_ivac_q0104_c_obs']   & [`zero_a_ivac_q0104_n_obs']	& &	///
							& [`zero_a_ivac_q0508_c_obs']   & [`zero_a_ivac_q0508_n_obs']	& \\
			
tex \multicolumn{8}{l}{ } \\							
tex $x ~~~Total balance: collections and delinquencies: & `deli_a_ivac_q0104_c_co' 		& `deli_a_ivac_q0104_n_co' 		& `deli_x_ivac_q0104_x_pv' & ///
							& `deli_a_ivac_q0508_c_co' 		& `deli_a_ivac_q0508_n_co' 		& `deli_x_ivac_q0508_x_pv' \\	
tex							& `deli_a_ivac_q0104_c_se' 		& `deli_a_ivac_q0104_n_se' 		& & ///
							& `deli_a_ivac_q0508_c_se' 		& `deli_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`deli_a_ivac_q0104_c_obs']   & [`deli_a_ivac_q0104_n_obs']	& &	///
							& [`deli_a_ivac_q0508_c_obs']   & [`deli_a_ivac_q0508_n_obs']	& \\			
			
tex \multicolumn{8}{l}{ } \\							
tex $x ~~~Any auto loan or lease: & `auto_a_ivac_q0104_c_co' 		& `auto_a_ivac_q0104_n_co' 		& `auto_x_ivac_q0104_x_pv' & ///
							& `auto_a_ivac_q0508_c_co' 		& `auto_a_ivac_q0508_n_co' 		& `auto_x_ivac_q0508_x_pv' \\	
tex							& `auto_a_ivac_q0104_c_se' 		& `auto_a_ivac_q0104_n_se' 		& & ///
							& `auto_a_ivac_q0508_c_se' 		& `auto_a_ivac_q0508_n_se' 		& \\							
tex  				 		& [`auto_a_ivac_q0104_c_obs']   & [`auto_a_ivac_q0104_n_obs']	& &	///
							& [`auto_a_ivac_q0508_c_obs']   & [`auto_a_ivac_q0508_n_obs']	& \\

														
tex \bottomrule \\
tex	\end{tabular} }
texdoc close


